package com.nbsaas.boot;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

public class LargeFileReaderNIO {
    public static void main(String[] args) {
        Path filePath = Paths.get("E:\\data\\rockyou2024.txt");

        try (FileChannel fileChannel = FileChannel.open(filePath, StandardOpenOption.READ)) {
            ByteBuffer buffer = ByteBuffer.allocate(8192); // 8KB buffer
            while (fileChannel.read(buffer) > 0) {
                buffer.flip(); // Prepare the buffer to be read
                while (buffer.hasRemaining()) {
                    System.out.print((char) buffer.get());
                }
                buffer.clear(); // Prepare the buffer for the next read
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
